from appium import webdriver



desired_caps={}
desired_caps['platformName']='Android'
desired_caps['version']='7.1.1'
desired_caps['deviceName']='HGAFQ94U'#这是测试机的型号，可以查看手机的关于本机选项获得
desired_caps["unicodeKeyboard"] = True # 使用unicode编码方式发送字符串
desired_caps["resetKeyboard"] = True   # 隐藏键盘
# desired_caps['app'] = PATH('D:\\qq.apk')#被测试的App在电脑上的位置
desired_caps['recreateChromeDriverSessions'] = True
desired_caps['appPackage'] = 'cn.com.fwd.eapp.uat'
desired_caps['appActivity'] = 'cn.com.fwd.eapp.uat.activity.SplashActivity'
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
class windowssize():
    def getSize():
        x = dr.get_window_size()['width']
        y = dr.get_window_size()['height']
        return (x, y)

    # 屏幕向上滑动
    def swipeUp(t):
        l = getSize()
        x1 = int(l[0] * 0.5)  # x坐标
        y1 = int(l[1] * 0.75)  # 起始y坐标
        y2 = int(l[1] * 0.25)  # 终点y坐标
        dr.swipe(x1, y1, x1, y2, t)

    # 屏幕向下滑动
    def swipeDown(t):
        l = getSize()
        x1 = int(l[0] * 0.5)  # x坐标
        y1 = int(l[1] * 0.25)  # 起始y坐标
        y2 = int(l[1] * 0.75)  # 终点y坐标
        dr.swipe(x1, y1, x1, y2, t)

    # 屏幕向左滑动
    def swipLeft(t):
        l = getSize()
        x1 = int(l[0] * 0.75)
        y1 = int(l[1] * 0.5)
        x2 = int(l[0] * 0.05)
        dr.swipe(x1, y1, x2, y1, t)

    # 屏幕向右滑动
    def swipRight(t):
        l = getSize()
        x1 = int(l[0] * 0.05)
        y1 = int(l[1] * 0.5)
        x2 = int(l[0] * 0.75)
        dr.swipe(x1, y1, x2, y1, t)

# 调用向左滑动
swipLeft(1000)
sleep(3)
# 调用向右滑动
swipRight(1000)
#调用向上滑动
swipeUp(1000)
#调用向下滑动
swipeDown(1000)